﻿using B.S.Orders.Domain;
using SqlSugar;
namespace B.S.Orders.Infrastructure
{
    public class SCDBContext
    {
        public SqlSugarClient Db { get; }

        public SCDBContext()
        {
            Db = new SqlSugarClient(new ConnectionConfig()
            {
                DbType = DbType.SqlServer,
                ConnectionString = "Server=10.223.8.81;DataBase=wanghaoran1;Uid=sa;Pwd=123456;Encrypt=True;TrustServerCertificate=True;",
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,
            });

            Db.DbMaintenance.CreateDatabase();
            Db.CodeFirst.InitTables(typeof(OrdersModel));
            Db.CodeFirst.InitTables(typeof(Documents));
            Db.CodeFirst.InitTables(typeof(ProjectModel));
            Db.CodeFirst.InitTables(typeof(ProjectType));
            Db.CodeFirst.InitTables(typeof(DispatchDetails));
            Db.CodeFirst.InitTables(typeof(DispatchProduct));
            Db.CodeFirst.InitTables(typeof(Outsourcing));
            Db.CodeFirst.InitTables(typeof(OutsourcingDeetail));
            Db.CodeFirst.InitTables(typeof(Process));
            Db.CodeFirst.InitTables(typeof(Equipment));
            Db.CodeFirst.InitTables(typeof(Personnel));

            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine($"执行SQL:{sql},参数{sql}");
            };
        }
    }
}
